#include "StdAfx.h"
#include "DBSession.h"
#include "DB.h"
#include "DBClient.h"
#include "../GameDefine/Log.h"


CodesHandler<DBSession> dbsessiontable[DC_Type_Nums] =
{
	{"DC_PlayerAuthSession", DC_PlayerAuthSession, &DBSession::HandlePlayerAuthSession}
};

void DBSession::ExecuteOpcode(tagMessage* m)
{
	if(m->dwHDCode<NS_Type_Nums)
		(this->*(dbsessiontable[m->dwHDCode].handler))(m);
	else
	{
		assert(0);
		sLog.Write("code is over");
	}
}

DBSession::DBSession(DBClient* p, DWORD dwGameID)
{
	m_dwGameID = dwGameID;
	m_pClient = p;
}

DBSession::~DBSession(void)
{
}

DWORD DBSession::GetGameID()
{
	return m_dwGameID;
}

void DBSession::Update()
{
	m_pClient->HandleMessage();
}

DWORD DBSession::HandleLoadRoleInfor(LPVOID lp)
{
	DWORD dwSize = 0;
	//sDB.LoadRoleInfor(lp, dwSize);
	//m_pClient->AddSendMsg(lp, dwSize);
	return 0;
}

void DBSession::HandlePlayerAuthSession(tagMessage* m)
{
	tagDS_PlayerAuthSession msg;
	tagDC_PlayerAuthSession *pMsg = (tagDC_PlayerAuthSession*)m;
	msg.dwRst =  sDB.PlayerAuthSession(m);
	if(EAS_Sucessed == msg.dwRst)	
		IMSG(_T("%s Login"), conversion::astr2wstr(pMsg->szName).c_str());
	strncpy_s(msg.szName, 32, pMsg->szName, 32);
	m_pClient->AddSendMsg(&msg, msg.dwSize);
}

